package net.cjw.initsb.utils;

import java.util.Random;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class PasswordUtils {

	static Logger logger = LoggerFactory.getLogger(PasswordUtils.class);

	public static String buildSalt() {

		char[] cs = new char[] { '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '_', '=', ';', ':',
				',', '.', '<', '>' };
		char tmp;
		Random random = new Random();
		int randomInt;
		for (int i = 0; i < cs.length; i++) {
			randomInt = random.nextInt(cs.length);
			tmp = cs[randomInt];
			cs[randomInt] = cs[i];
			cs[i] = tmp;
		}
		String salt = UUIDBuild.createUUId() + String.valueOf(cs);
		logger.info("salt: " + salt);
		return salt;

	}

	public static String buildPassword(String password, String salt) {
		String md5SaltPassword = MD5Util.getMD5(password + salt);
		logger.info("md5SaltPassword: " + md5SaltPassword);
		return md5SaltPassword;

	}
}
